package com.huluobo.a2110mvpimdemo.addFriend;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huluobo.a2110mvpimdemo.R;
import com.huluobo.a2110mvpimdemo.base.BaseActivity;

public class AddFriendActivity extends BaseActivity<AddFriendContract.View, AddFriendPresenter> implements AddFriendContract.View {
    private ImageView back;
    private TextView title;
    private EditText username, reason;
    private Button addFriendBtn;

    @Override
    public void onAddSuccess() {
        dismissProgressDialog();
        runOnUiThread(() -> {
            Toast.makeText(this, "发送好友请求成功,清对方登录一次即可添加成功", Toast.LENGTH_SHORT).show();
        });
    }

    @Override
    public void onAddFailed(String error) {
        dismissProgressDialog();
        runOnUiThread(() -> {
            Toast.makeText(this, "发送好友请求失败" + error, Toast.LENGTH_SHORT).show();
        });
    }

    @Override
    protected void initData() {
        presenter = new AddFriendPresenter();
    }

    @Override
    protected void initView() {
        title = findViewById(R.id.header_title);
        back = findViewById(R.id.header_back);
        username = findViewById(R.id.addFriend_username);
        reason = findViewById(R.id.addFried_reason);
        addFriendBtn = findViewById(R.id.addFriend_btn);

        title.setText("添加好友");
        back.setVisibility(View.VISIBLE);
        back.setOnClickListener(v -> {
            finish();
        });

        addFriendBtn.setOnClickListener(v -> {
            showProgressDialog("正在发送好友请求...");
            presenter.add(username.getText().toString(), reason.getText().toString());
        });
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_add_friend;
    }
}